const path = require('path')
const resolve = (dir) => path.join(__dirname, dir)
const { VUE_APP_BUILD_ROUTER } = process.env

const isDev = process.env.NODE_ENV === 'development'

module.exports = {
  productionSourceMap: false,
  parallel: false,
  publicPath: './',
  outputDir: `dist${VUE_APP_BUILD_ROUTER}`,
  assetsDir: "assets",
  // 选项...
  css: {
    sourceMap: false,
    loaderOptions: {
      sass: {
        sassOptions: { outputStyle: 'expanded' },
        prependData: `
         @import "./src/styles/variables.scss";
       `,
      },
    },
    extract: {
      // 打包后css文件名称添加时间戳
      filename: `css/[name].[contenthash].css`,
      chunkFilename: `css/[name].[contenthash].css`
    }
  },
  configureWebpack: (config) => {
    return {
      resolve: {
        alias: {
          "@": resolve("src"),
        },
      },
      output: {
        filename: isDev ? '[name].js' : `js/[name].[contenthash].js`,
        chunkFilename: isDev ? '[name].js' : `js/[name].[contenthash].js`
      }
    }
  }
}
